package cn.org.eshow.model;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 微信信息资源
 */
@Entity
@Table(name = "weixin_val")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class WeixinVal extends BaseObject implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final Long EXPIRES_IN = 1000 * 7200l;// 7200秒

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(name = "add_time", nullable = false, length = 0)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime = new Date();// 添加时间

    @Column(name = "update_time", nullable = false, length = 0)
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime = new Date();// 修改时间

    @Column(name = "category")
    private String category;// 分类（用户user）

    @Column(name = "type")
    private String type;// 类型（accessToken,jsApiTicket）

    @Column(name = "val")
    private String val;// 值

    @Column(name = "expires_in")
    private Long expiresIn;// 过期时间（毫秒数）

    @Column
    private Boolean enabled;// 是否可用

    /**
     * default constructor
     */
    public WeixinVal() {
    }

    public WeixinVal(String category, String type, String val, Long expiresIn) {
        super();
        this.addTime = new Date();
        this.updateTime = new Date();
        this.category = category;
        this.type = type;
        this.val = val;
        this.expiresIn = expiresIn;
        this.enabled = Boolean.TRUE;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getAddTime() {
        return addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getVal() {
        return val;
    }

    public void setVal(String val) {
        this.val = val;
    }

    public Long getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("id", this.id)
                .append("addTime", this.addTime)
                .append("updateTime", this.updateTime)
                .append("type", this.type)
                .append("val", this.val)
                .append("expiresIn", this.expiresIn)
                .append("enabled", this.enabled)
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        WeixinVal weixinVal = (WeixinVal) o;

        if (addTime != null ? !addTime.equals(weixinVal.addTime) : weixinVal.addTime != null)
            return false;
        if (updateTime != null ? !weixinVal.equals(weixinVal.updateTime) : weixinVal.updateTime != null)
            return false;
        if (type != null ? !type.equals(weixinVal.type)
                : weixinVal.type != null)
            return false;
        if (val != null ? !val.equals(weixinVal.val)
                : weixinVal.val != null)
            return false;
        if (expiresIn != null ? !expiresIn.equals(weixinVal.expiresIn) : weixinVal.expiresIn != null)
            return false;
        if (enabled != null ? !enabled.equals(weixinVal.enabled) : weixinVal.enabled != null)
            return false;
        return true;

    }

    @Override
    public int hashCode() {
        int result = 0;

        result = 31 * result + (id != null ? id.hashCode() : 0);
        result = 31 * result + (addTime != null ? addTime.hashCode() : 0);
        result = 31 * result + (updateTime != null ? updateTime.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        result = 31 * result + (val != null ? val.hashCode() : 0);
        result = 31 * result + (expiresIn != null ? expiresIn.hashCode() : 0);
        result = 31 * result + (enabled != null ? enabled.hashCode() : 0);
        return result;

    }

}